import demo.service.RemoteService;
import demo.service.RemoteServiceImpl;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.rmi.RemoteException;

public class Main {

    public static void main(String[] args){
        String name = "service-cc";
        try{
            RemoteService service = new RemoteServiceImpl(name);
            //初始化命名空间
            Context namingContext = new InitialContext();
            //将名称绑定到对象,即向命名空间注册已经实例化的远程服务对象
            namingContext.rebind("rmi://localhost/" + name, service);
        } catch(RemoteException e){
            e.printStackTrace();
        } catch(NamingException e){
            e.printStackTrace();
        }
        System.out.println("服务器向命名表注册了1个远程服务对象！");
    }
}
